package com.fengwei.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;

/**
 * @author JamesLee
 */
public class VerifyException extends RuntimeException {
    private final static Logger logger = LoggerFactory.getLogger(VerifyException.class);

    public Enum errorStatus;
    public String errCd;
    public String errorDesc;

    public Enum getErrorStatus() {
        return errorStatus;
    }

    public VerifyException() {
        super();
    }

    public VerifyException(Enum errorStatus) {
        this.setErrorStatus(errorStatus);
    }

    public void setErrorStatus(Enum errorStatus) {
        this.errorStatus = errorStatus;
        try {
            Class clazz = errorStatus.getDeclaringClass();
            Method toCode = clazz.getMethod("getpCode");
            Method toName = clazz.getMethod("getpName");
            this.errCd = (String) toCode.invoke(errorStatus);
            this.errorDesc = (String) toName.invoke(errorStatus);
        } catch (Exception e) {
            logger.error("Error:", e);
        }
    }

    public void setErrCd(String errCd) {
        this.errCd = errCd;
    }

    public String getErrCd() {
        return errCd;
    }

    public String getErrorDesc() {
        return errorDesc;
    }

    public void setErrorDesc(String errorDesc) {
        this.errorDesc = errorDesc;
    }
}
